/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package eac.ucm;
import eac.view.EACenter;
import eac.model.ComponentModel;
import eac.model.ValueModel;
import database.Select;
import javax.swing.table.DefaultTableModel;
import java.sql.*;
import javax.swing.*;

/**
 *
 * @author Vitamin
 */

public class RefreshTable {
    private Select dbSelect;
    private String id;
    private String sql;
    private String[] data = new String[10];
    private DefaultTableModel modelA;
    private DefaultTableModel modelB;
    private ComponentModel component;
    private ValueModel value;
    private ResultSet result;
    private JTable tbAchievement;
    private JTable tbCourse;
    private String tid;
    private static RefreshTable local;

    public RefreshTable()
    {
        dbSelect=new Select();
        component=EACenter.getInstance().getComponentModel();
        value=EACenter.getInstance().getValueModel();
        tbAchievement=component.getAchievement();
        tbCourse=component.getCourse();
        modelA=(DefaultTableModel)tbAchievement.getModel();
        modelB=(DefaultTableModel)tbCourse.getModel();
        id=value.getId();
        tid=value.getTid();
        local=this;
    }

    public static RefreshTable getInstance()
    {
        if(local==null)
        {
            local=new RefreshTable();
        }
        return local;
    }
    
    public void initStudentTable()
    {
        modelA.setRowCount(0);
    }

    public void initTeacherTable()
    {
        modelB.setRowCount(0);
    }

    public void showAchievement(String[] tp)
    {
        try{
        local.data=tp;
        modelA.addRow(data);
        tbAchievement.invalidate();
        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }

    }

    public void showCourse(String[] tp)
    {
        try{
            local.data=tp;
            modelB.addRow(data);
            tbCourse.invalidate();
            
        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }

    }


}
